package study.springcloud.config.nacos.controller;

import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import study.springcloud.config.nacos.support.bean.Bean1;
import study.springcloud.config.nacos.support.bean.Bean2;
import study.eggs.result.Result;
import study.eggs.result.Results;

import java.util.Map;

@Slf4j
@RestController
public class _2_BeanController {

    @Autowired
    private Bean1 bean1;
    @Autowired
    private Bean2 bean2;

    @RequestMapping("/config/bean1")
    public Result propertiesV1() {
        log.info(">>>>>> {}", bean1.getClass().getSimpleName());

        Map<String, Object> data = Maps.newHashMap();
        data.put("name", bean1.getName());
        data.put("age", bean1.getAge());
        return Results.ok(data);
    }

    @RequestMapping("/config/bean2")
    public Result propertiesV2() {
        log.info(">>>>>> {}", bean2.getClass().getSimpleName());
        return Results.ok(bean2);
    }
}
